package org.example.physics_engine.geometry;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

/*轴对齐包围盒的实现，就是一个框？*/
/*一个AxisAlignBoundingBox具有定义方框的最小和最大坐标。*/
@Data
@NoArgsConstructor
@AllArgsConstructor
public class AxisAlignBoundingBox {

    //零点定在左下方
    //左边框的X坐标
    public double minX;
    //右边框的X坐标
    public double minY;
    //下边框的Y坐标
    public double maxX;
    //上边框的Y坐标
    public double maxY;

    public AxisAlignBoundingBox(AxisAlignBoundingBox aabb) {
        this.minX = aabb.minX;
        this.minY = aabb.minY;
        this.maxX = aabb.maxX;
        this.maxY = aabb.maxY;
    }

    //判断本Box与参数Box是否重叠
    public boolean overlap(AxisAlignBoundingBox aabb) {
        if (this.maxX < aabb.minX || this.minX > aabb.maxX || this.minY > aabb.maxY || this.maxY < aabb.minY)
            return false;
        return true;
    }

    //将Box按参数坐标平移
    public void translate(double x, double y) {
        this.minX += x;
        this.maxX += x;
        this.minY += y;
        this.maxY += y;
    }

    //将Box按给定Vector平移
    public void translate(Vector2d vector) {
        this.translate(vector.x, vector.y);
    }

}
